package com.hmall.trade.utils;


import com.hmall.common.utils.BeanUtils;

import java.util.ArrayList;
import java.util.List;

public class BeanUtilsExt {
    public static <S, T> List<T> copyList(List<S> sourceList, Class<T> targetClass) {
        List<T> targetList = new ArrayList<>();
        for (S source : sourceList) {
            try {
                T target = targetClass.newInstance();
                BeanUtils.copyProperties(target, source); // 拷贝属性
                targetList.add(target);
            } catch (Exception e) {
                throw new RuntimeException("列表拷贝失败", e);
            }
        }
        return targetList;
    }
}
